package com.github.tj123.common;

import com.github.tj123.common.validate.ValidateUtil;
import com.github.tj123.common.validate.impl.NotValidException;

/**
 * 可验证的类
 */
public interface Validatable {

    /**
     * 验证
     *
     * @return
     */
    default <V extends Validatable> V validate() throws NotValidException {
        V v = (V) this;
        ValidateUtil.validate(v);
        return v;
    }

    /**
     * 只验证一个字段
     *
     * @return
     */
    default <V extends Validatable> V validate(String fieldName) throws NotValidException {
        V v = (V) this;
        ValidateUtil.validate(v,fieldName);
        return v;
    }

    /**
     * 只验证多个字段
     *
     * @return
     */
    default <V extends Validatable> V validate(String... fieldNames) throws NotValidException {
        V v = (V) this;
        ValidateUtil.validate(v,fieldNames);
        return v;
    }

}
